package com.yan.deezer.ui.fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockDialogFragment;
import com.yan.deezer.R;

public class MyAlertDialogFragment extends SherlockDialogFragment {

	public static MyAlertDialogFragment newInstance(int title) {

		MyAlertDialogFragment frag = new MyAlertDialogFragment();
		Bundle args = new Bundle();
		args.putInt("title", title);
		frag.setArguments(args);
		return frag;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		int title = getArguments().getInt("title");

		final TextView message = new TextView(getActivity());
		final SpannableString s = new SpannableString(getActivity().getText(
				R.string.alert_dialog_body));
		Linkify.addLinks(s, Linkify.ALL);
		// message.setTextColor(android.R.color.darker_gray);
		message.setText(s);
		message.setTextSize(15);
		message.setPadding(5, 5, 5, 5);
		message.setBackgroundResource(R.drawable.abs__ab_bottom_solid_light_holo);
		message.setMovementMethod(LinkMovementMethod.getInstance());

		return new AlertDialog.Builder(getActivity())
				.setIcon(R.drawable.alert)
				.setTitle(title)
				.setView(message)
				.setPositiveButton(R.string.alert_dialog_ok,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int whichButton) {
								doPositiveClick();
							}
						})

				.create();
	}

	public static void doPositiveClick() {
		// Do stuff here, Yan.
	}

	public static void doNegativeClick() {
		// Do stuff here, Yan.
	}
}
